package com.wk.springframework.support;

import com.wk.springframework.common.exception.BeanException;
import com.wk.springframework.config.BeanDefinition;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFactory implements BeanDefinitionRegistry {

    private final Map<String, BeanDefinition> beanDefinitionMap = new HashMap<>();

    @Override
    public void registryBeanDefinition(String beanName, BeanDefinition beanDefinition) {
        this.beanDefinitionMap.put(beanName, beanDefinition);
    }

    @Override
    public BeanDefinition getBeanDefinition(String beanName) {
        BeanDefinition beanDefinition = this.beanDefinitionMap.get(beanName);
        if (Objects.isNull(beanDefinition)) throw new BeanException("beanName :" + beanName + "have not registry");
        return beanDefinition;
    }
}
